//
//  DishThumbFlipView.m
//  XRmenu
//
//  Created by loufq on 11-3-29.
//  Copyright 2011 E0571. All rights reserved.
//

#import "DishThumbFlipView.h"
#import "XRRateView.h"
#import "DishThumbView.h"
#import "XRmenuHelper.h"

@implementation DishThumbFlipView

@synthesize item;

#define kTagTitle 401
#define kTagDes 402
#define kTagCommendText 403

-(void)dealloc
{
	self.item = nil;
	[super dealloc];
}

-(id)initWithThumbView:(DishThumbView*)aDishThumbView
{
	self =[super initWithFrame:aDishThumbView.wrapper.frame];
	if (self) {
		self.item = aDishThumbView.item;
			[self initFresh];
	}
	return self;
}

-(void)initFresh
{
	
	[[self viewWithTag:kTagTitle] removeFromSuperview];
	[[self viewWithTag:kTagDes] removeFromSuperview];
	[[self viewWithTag:kTagCommendText] removeFromSuperview];
	
	NSString* dishName= @"";
	NSString* dishDesc= @"";
	dishName = JsonFiled(item.pName);
	NSInteger iType = [item.pType intValue];
	switch (iType) {
		case ProductTypeDish:
		{
			dishDesc = [NSString stringWithFormat:@"%@:%@\n%@:%@", loc(@"食材"),[XRmenuHelper getCurrentEx:item].dMaterialEx, 
						loc(@"烹饪"),[XRmenuHelper getCurrentEx:item].dRecipesEx];
			break;	
		}	
		case ProductTypeSeasonDsih:
		{
			//DebugLog(@"套餐信息：%@-%@-%@",
//					 item.rsToSeasonDish.sCookeryOptions,
//					 item.rsToSeasonDish.sName,
//					 item.rsToSeasonDish.sSpellCode);
			dishDesc = [NSString stringWithFormat:@"%@",loc(item.rsToSeasonDish.sCookeryOptions)];	
			break;
		}
		case ProductTypeCigarette:
		{ 
			dishDesc = [NSString stringWithFormat:@"%@:%@\n%@:%@\n%@\n%@\n",
						loc(@"类型"),loc(item.rsToCigarette.cPackage),
						loc(@"规格"), loc(item.rsToCigarette.cSpecification),
						loc(item.rsToCigarette.cTar),  
						loc(item.rsToCigarette.cNicotine)];
			break;
		}
		case ProductTypeSetMeal://套餐
		{
			NSArray * products = [item.rsInSetMeal.rsIncludeProduct allObjects]; 
			for (Product* i in products){
				DebugLog(@"套餐信息：%@", i.pName );
			}  
			dishDesc = [NSString stringWithFormat:@"%@",loc(item.rsInSetMeal.sSummary)];
			break;
		}
		case ProductTypeDrink:
		{
			dishDesc = [NSString stringWithFormat:@"%@:%@\n%@:%@\n%@:%@", 
						loc(@"产地"),loc(item.rsToDrink.dPlace), 
						loc(@"年份"),loc(item.rsToDrink.dYear),
						loc(@"度数"),loc(item.rsToDrink.dTemperature)];
		}
		default:
			break;
	}
	
	UIFont* font = [UIFont fontWithName:@"Arial" size:12];
	UIFont* font2 = [UIFont fontWithName:@"Arial" size:12]; 
	self.layer.borderWidth =1;
	self.layer.borderColor =[UIColor grayColor].CGColor;
	
	CGSize s = CGSizeZero;
	NSInteger allHeight = 0;
	CGRect scrollFrame = CGRectMake(3, 3 , self.frame.size.width-6, self.frame.size.height - 25-6);
	UIScrollView* sv = [[UIScrollView alloc] initWithFrame:scrollFrame];
	
	
	s = [dishName sizeWithFont:font constrainedToSize:CGSizeMake(scrollFrame.size.width, 100) lineBreakMode:UILineBreakModeWordWrap]; 
	allHeight+=s.height+10;
	//名字
	UITextView* tv =[[UITextView alloc] initWithFrame:CGRectMake(0, 0, scrollFrame.size.width, s.height+10)];
	tv.scrollEnabled = NO;
	[tv setBackgroundColor:[UIColor clearColor]];
	[tv setTextColor:[UIColor whiteColor]];
	tv.editable = NO;
	tv.tag =kTagTitle;
	[tv setText:dishName];
	[sv addSubview:tv]; 
	[tv release];
	//介绍
	s =[dishDesc sizeWithFont:font2 constrainedToSize:CGSizeMake(scrollFrame.size.width, 100) lineBreakMode:UILineBreakModeWordWrap]; 
	
	tv =[[UITextView alloc] initWithFrame:CGRectMake(0, allHeight+3, scrollFrame.size.width, s.height<100?100:s.height)];
	tv.tag =kTagDes;
	[tv setTextColor:[UIColor grayColor]];
	[tv setBackgroundColor:[UIColor clearColor]];
	tv.editable = NO;
	[tv setText:dishDesc];
	[sv addSubview:tv];
	[tv release];
	[self addSubview:sv];
	[sv release];
	 
	int iTop = self.frame.size.height -18 ;
	int iLeft = 4;
	
	NSString* strRecmand =  [NSString stringWithFormat:@"%@:", loc(@"评价")];
	tv.tag =kTagCommendText;
	s = [strRecmand sizeWithFont:[UIFont fontWithName:@"Arial" size:12]];
	CGRect f = CGRectMake(iLeft, iTop ,s.width, s.height); 
	
	UILabel* lbl =[[UILabel alloc] initWithFrame: f];
	[lbl setText:strRecmand];
	[lbl setTextColor:[UIColor whiteColor]];
	lbl.backgroundColor = [UIColor clearColor];
	[lbl setFont:[UIFont fontWithName:@"Arial" size:12]];
	[self addSubview:lbl];
	[lbl release];
	
	iLeft += s.width +10;
	XRRateView* rv =[[XRRateView alloc] initWithFrame:CGRectMake(iLeft+2, self.frame.size.height -25 , 80, 25)];
	rv.notSelectedImage = getSkinImg(@"RateView/star_empty.png");
	rv.halfSelectedImage = getSkinImg(@"RateView/star_half.png");
	rv.fullSelectedImage = getSkinImg(@"RateView/star_full.png"); 
	rv.editable = NO ;
	rv.rating = [item.pScoreCount floatValue];
	rv.maxRating = 5 ;
	rv.midMargin = 1;
	[self addSubview:rv];
	[rv release];
	
	UIButton* btn =[[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width-45, self.frame.size.height-27, 40, 22)];
	[btn setBackgroundImage:getSkinImg(@"View/Album View/switchtophoto.png") forState:UIControlStateNormal];
	[self addSubview:btn];
	[btn release];
}

 

@end
